package com.yc.star.booksystem.mapper;

import com.yc.star.booksystem.model.BookInfo;
import com.yc.star.booksystem.model.PageRequest;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface BookMapper {

    @Select("select * from book_info where status != 0 order by id desc limit #{offset},#{pageSize}")
    List<BookInfo> getBookList(PageRequest pageRequest);

    @Insert("insert into book_info(book_name,author,count,price,publish,status) " +
            "values (#{bookName},#{author},#{count},#{price},#{publish},#{status})")
    Integer insertBook(BookInfo bookInfo);

    @Select("select count(*) from book_info where status != 0")
    Integer getCount();

    @Select("select * from book_info where status != 0 and id = #{id}")
    BookInfo queryBookById(Integer id);

    Integer updateBook(BookInfo bookInfo);

    void batchDelete(List<Integer> ids);

}
